# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=innoextract
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.9
pkgrel=8
pkgdesc="A tool to extract installers created by Inno Setup (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url="https://constexpr.org/innoextract/"
license=("spdx:MIT")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-python")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-boost"
         "${MINGW_PACKAGE_PREFIX}-bzip2"
         "${MINGW_PACKAGE_PREFIX}-libiconv"
         "${MINGW_PACKAGE_PREFIX}-xz"
         "${MINGW_PACKAGE_PREFIX}-zlib")
source=("https://constexpr.org/innoextract/files/${_realname}-${pkgver}.tar.gz"{,.sig})
sha256sums=('6344a69fc1ed847d4ed3e272e0da5998948c6b828cb7af39c6321aba6cf88126'
            'SKIP')
validpgpkeys=("ADE9653703D4ADE0E997758128555A66D7E1DEC9") # Daniel Scharrer <daniel@constexpr.org>

build() {
  mkdir -p ${srcdir}/build-${MSYSTEM} && cd ${srcdir}/build-${MSYSTEM}

  declare -a _extra_config
  if check_option "debug" "n"; then
    _extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    _extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -Wno-dev \
    -G"Ninja" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    "${_extra_config[@]}" \
    -DUSE_STATIC_LIBS=OFF \
    -DPYTHON_EXECUTABLE=${MINGW_PREFIX}/bin/python \
    ../${_realname}-${pkgver}

  ${MINGW_PREFIX}/bin/cmake.exe --build ./
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake.exe --install ./

  install -Dm644 ${srcdir}/${_realname}-${pkgver}/README.md \
    "${pkgdir}${MINGW_PREFIX}/share/doc/${_realname}/README.md"
  install -Dm644 ${srcdir}/${_realname}-${pkgver}/CHANGELOG \
    "${pkgdir}${MINGW_PREFIX}/share/doc/${_realname}/CHANGELOG"
  install -Dm644 ${srcdir}/${_realname}-${pkgver}/LICENSE \
    "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
